package com.leetcode;

/**
 * @author yijy
 * @description
 * @create 2021/3/9 下午3:02
 **/
public class SumForStr {

    public static void main(String[] args) {
        String s1 = "1234567890";
        String s2 = "9239566892";
        System.out.println(new SumForStr().sum(s1,s2));
    }

    public String sum(String s1, String s2){
        int n1 = s1.length()-1;
        int n2 = s2.length()-1;
        int carry = 0;
        String sb = "";
        while (n1 >= 0 || n2 >= 0 || carry > 0) {
            int a1 = 0;
            if(n1 >=0 ){
                a1 = Integer.parseInt(s1.charAt(n1)+"");
            }
            int a2 = 0;
            if(n2 >= 0 ){
                a2 = Integer.parseInt(s2.charAt(n1)+"");
            }
            int total = a1+a2 +carry;
            carry = total/10;
            int cur = total%10 ;
            sb = cur+sb;
            n1 --;
            n2 --;
        }
        return sb;
    }
}
